﻿using Microsoft.AspNet.Identity;
using Paperless.Entities;
using Paperless.Models;
using System.Threading.Tasks;
using System.Web.Http;
using System.Linq;
using AutoMapper;
using System.Collections.Generic;

namespace Paperless.Controllers
{
    public class UserController : ApiController
    {
        public UserManager<User> Repository { get; private set; }

        public UserController(UserManager<User> repository)
        {
            Repository = repository;
        }

        public IHttpActionResult Get(long? locationId = null)
        {
            var query = Repository.Users;

            if (locationId.HasValue)
            {
                query = query.Where(x => x.LocationId == locationId);
            }

            var result = Mapper.Map<IEnumerable<UserSearchModel>>(query.ToList());

            return Ok(result);
        }
    }
}